package com.lingnan.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lingnan.mapper.RecruitingPlayersMapper;
import com.lingnan.mapper.SelfActiveMapper;
import com.lingnan.pojo.RecruitingPlayers;
import com.lingnan.pojo.SelfActive;
import com.lingnan.service.RecruitingPlayersService;
import com.lingnan.vo.RecruitingPlayersVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 招募队员表 服务实现类
 * </p>
 *
 * @author 刘宇浩
 * @since 2022-03-13
 */
@Service
public class RecruitingPlayersServiceImpl extends ServiceImpl<RecruitingPlayersMapper, RecruitingPlayers> implements RecruitingPlayersService {

    @Autowired
    private RecruitingPlayersMapper recruitingPlayersMapper;
    @Autowired
    private SelfActiveMapper selfActiveMapper;

    @Override
    public boolean publishPlayers(RecruitingPlayersVo recruitingPlayersVo) {
        RecruitingPlayers recruitingPlayers = new RecruitingPlayers();
        recruitingPlayers.setName(recruitingPlayersVo.getName());
        recruitingPlayers.setBeginTime(recruitingPlayersVo.getBeginTime());
        recruitingPlayers.setEndTime(recruitingPlayersVo.getEndTime());
        recruitingPlayers.setContent(recruitingPlayersVo.getContent());
        recruitingPlayers.setPhone(recruitingPlayersVo.getPhone());
        recruitingPlayers.setPlace(recruitingPlayersVo.getPlace());
        recruitingPlayers.setSponsor(recruitingPlayersVo.getSponsor());
        recruitingPlayers.setType(recruitingPlayersVo.getType());
        int insert = recruitingPlayersMapper.insert(recruitingPlayers);
        if (insert>0){
            //将发布的招募活动设置到招募人的个人活动里
            SelfActive selfActive = new SelfActive();
            selfActive.setNo(recruitingPlayersVo.getNo());
            selfActive.setName(recruitingPlayersVo.getName());
            selfActive.setPlace(recruitingPlayersVo.getPlace());
            selfActive.setBeginTime(recruitingPlayersVo.getBeginTime());
            selfActive.setEndTime(recruitingPlayersVo.getEndTime());
            selfActive.setContent(recruitingPlayersVo.getContent());
            selfActive.setActiveId(recruitingPlayersVo.getId());
            selfActiveMapper.insert(selfActive);
        }
        return insert > 0;
    }
}
